home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Snippets / Mounting AppleShare / Mounting AppleShare.c < prev   
Encoding:
Text File  |  1994-04-21  |  2.4 KB  |  73 lines  |  [TEXT/R*ch]

  1.     myMount=(AFPVolMountInfo *)NewPtr(sizeof(AFPVolMountInfo));  /* allocate
  2. space for mount record */
  3.  
  4.     myMount->media = AppleShareMediaType;  /*  fill in mounting information - general */
  5.     myMount->flags = 0;
  6.     myMount->nbpInterval = 0;
  7.     myMount->nbpCount = 0;
  8.     myMount->uamType = kPassword;
  9.     
  10.     myMount->zoneNameOffset = 24;  /* mounting info -  my offsets for the data from the */
  11.     myMount->serverNameOffset = 57;  /* beginning of the 'myMount' record */
  12.     myMount->userNameOffset = 117;
  13.     myMount->userPasswordOffset = 149;
  14.     myMount->volPasswordOffset = 158;
  15.     myMount->volNameOffset = 89;
  16.     
  17.     zoneName=GetString(BASE_RES_ID);    /*  actual mounting information.. must be in pascal strings */
  18.     
  19.     errorCode=(long)ResError();
  20.     if (errorCode != 0)
  21.         HandleError((long)errorCode);
  22.  
  23.     strcpy(myMount->AFPData, PtoCstr(*((Str255 *)*zoneName)));
  24.     ReleaseResource((Handle)zoneName);
  25.     CtoPstr(myMount->AFPData);
  26.  
  27.     strcpy(myMount->AFPData+UNAMEOFFSET, PtoCstr(userName));
  28.     CtoPstr(myMount->AFPData+UNAMEOFFSET);
  29.     
  30.     strcpy(myMount->AFPData+UPASSOFFSET, gTempString);
  31.     CtoPstr(myMount->AFPData+UPASSOFFSET);
  32.     
  33.     strcpy(myMount->AFPData+VOLPASSOFFSET, "\0");
  34.     
  35.     CtoPstr(myMount->AFPData+VOLPASSOFFSET);
  36.     
  37.     myMount->length = sizeof(AFPVolMountInfo);
  38.     
  39.     pb=(ParmBlkPtr)NewPtr(sizeof(ParamBlockRec));
  40.     pb->ioParam.ioBuffer = (Ptr)myMount;
  41.         
  42.     do    /*   used because of multiple server compatibility   */
  43.     {
  44.         GetIndString(sName, BASE_RES_ID, strNum);    /*read server name from resource */
  45.         myErr=ResError();
  46.         if (sName[0] == NIL_POINTER)   /* if it didn't load a string */
  47.             {
  48.                 DisposPtr((Ptr)pb);
  49.                 DisposPtr((Ptr)myMount);
  50.                 return (OSErr)42;   /* tells program that the strings have run out */
  51.             }
  52.         strcpy(myMount->AFPData+SERVEROFFSET, PtoCstr(sName));
  53.         CtoPstr(myMount->AFPData+SERVEROFFSET); 
  54.  
  55.         GetIndString(sVol, BASE_RES_ID+1, strNum);  /* read volume name from resource */
  56.         myErr=ResError();  
  57.         if (myErr!=0)
  58.             HandleError((long)myErr);
  59.  
  60.         strcpy(myMount->AFPData+VOLOFFSET, PtoCstr(sVol));
  61.         CtoPstr(myMount->AFPData+VOLOFFSET);
  62.  
  63.         errorCode=PBVolumeMount(pb);   /* mount the actual volume */
  64.         strNum++;
  65.     }
  66.     while (errorCode!=0); /* close to the do statement */
  67.     volumename = (myMount->AFPData+VOLOFFSET);  /*set value of volumename to pass it */
  68.     
  69.     strcpy((char *)(volName), PtoCstr(*(Str255 *)volumename)); /* stores the volume name */
  70.     strcat((char *)(volName), ":");   /* for later unmounting....   */
  71.     CtoPstr((char *)volumename);
  72.     CtoPstr((char *)(volName));
  73.